package cn.fj.big.spring.httpclient.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * Created by LiJianXin on 2019/3/29 0029.
 */
@Component
@ConfigurationProperties(prefix = "http.client")
public class HttpClientProperties {

	private ConnectionManager connectionManager;

	private RequestConfig requestConfig;

	public ConnectionManager getConnectionManager() {
		return connectionManager;
	}

	public void setConnectionManager(ConnectionManager connectionManager) {
		this.connectionManager = connectionManager;
	}

	public RequestConfig getRequestConfig() {
		return requestConfig;
	}

	public void setRequestConfig(RequestConfig requestConfig) {
		this.requestConfig = requestConfig;
	}

	/**
	 * ConnectionManager配置项
	 *
	 * @see org.apache.http.impl.conn.PoolingHttpClientConnectionManager
	 */
	class ConnectionManager {

		private int defaultMaxPerRoute;
		private int maxTotal;

		public int getDefaultMaxPerRoute() {
			return defaultMaxPerRoute;
		}

		public void setDefaultMaxPerRoute(int defaultMaxPerRoute) {
			this.defaultMaxPerRoute = defaultMaxPerRoute;
		}

		public int getMaxTotal() {
			return maxTotal;
		}

		public void setMaxTotal(int maxTotal) {
			this.maxTotal = maxTotal;
		}
	}

	/**
	 * RequestConfig配置项
	 *
	 * @see org.apache.http.client.config.RequestConfig.Builder
	 */
	class RequestConfig {
		private int connectionRequestTimeout;
		private int connectTimeout;
		private int socketTimeout;

		public int getConnectionRequestTimeout() {
			return connectionRequestTimeout;
		}

		public void setConnectionRequestTimeout(int connectionRequestTimeout) {
			this.connectionRequestTimeout = connectionRequestTimeout;
		}

		public int getConnectTimeout() {
			return connectTimeout;
		}

		public void setConnectTimeout(int connectTimeout) {
			this.connectTimeout = connectTimeout;
		}

		public int getSocketTimeout() {
			return socketTimeout;
		}

		public void setSocketTimeout(int socketTimeout) {
			this.socketTimeout = socketTimeout;
		}
	}
}
